package ui;

import services.ContractServicempl;
import vo.Contract;

import java.util.List;
import java.util.Scanner;

public class ContractLogin { //合同页面
   static ContractServicempl contractServicempl=new ContractServicempl();//实现了对合同表进行变动的类
    static Scanner scanner=new Scanner(System.in);
    public static void Login(){
        System.out.println("1,添加数据");
        System.out.println("2,删除数据");
        System.out.println("3,修改数据");
        System.out.println("4,查询数据");
        System.out.println("5,查询所有数据");
        System.out.println("0,返回上一级");
        System.out.println("请输入你的选择");
        int fuctionNumbre=scanner.nextInt();
        switch (fuctionNumbre){
            case 1:
                if(add()){
                    System.out.println("添加成功");
                }else {
                    System.out.println("添加失败");
                }
            case 2:
                if(delet()){
                    System.out.println("删除完成");
                }else {
                    System.out.println("删除失败");
                }
            case 3:
                if(modify()){
                    System.out.println("修改完成");
                }else {
                    System.out.println("修改失败");
                }
            case 4:
                Contract contract=getcustombyid();
                System.out.println(contract);
                break;
            case 5:
                List<Contract> list=getall();
                for(Contract contract1:list){
                    System.out.println(contract1);
                }
                break;
            case 0:
                System.out.println("返回");
        }

    }

    private static boolean add() {
        System.out.println("请输入合同编号:");
        int id=scanner.nextInt();
        System.out.println("请输入客户名称:");
        String name=scanner.nextLine();
        System.out.println("请输入客户地址:");
        String address=scanner.nextLine();
        System.out.println("请输入订货时间:");
        String time=scanner.nextLine();
        System.out.println("请输入客户账号:");
        String custom_name=scanner.nextLine();
        System.out.println("请输入订单金额:");
        int price=scanner.nextInt();
        System.out.println("请输入商品编号");
        int invertory_id=scanner.nextInt();
        Contract contract=new Contract(id,name,address,time,custom_name,price,invertory_id);
       return contractServicempl.add(contract);
    }

    private static boolean delet() { //通id删除过
        System.out.println("请输入合同编号:");
        int id=scanner.nextInt();
        Contract contract=new Contract(id);
        return contractServicempl.delete(contract);
    }

    private static boolean modify() {
        System.out.println("请输入合同编号:");
        int id=scanner.nextInt();
        System.out.println("请输入客户名称:");
        String name=scanner.nextLine();
        System.out.println("请输入客户地址:");
        String address=scanner.nextLine();
        System.out.println("请输入订货时间:");
        String time=scanner.nextLine();
        System.out.println("请输入客户账号:");
        String custom_name=scanner.nextLine();
        System.out.println("请输入订单金额:");
        int price=scanner.nextInt();
        System.out.println("请输入商品编号");
        int invertory_id=scanner.nextInt();
        Contract contract=new Contract(id,name,address,time,custom_name,price,invertory_id);
        return contractServicempl.modify(contract);
    }

    private static Contract getcustombyid() {//通过合同的编号id来查询
        System.out.println("请输入合同编号:");
        int id=scanner.nextInt();
        return contractServicempl.getcustombyid(id);
    }

    private static List<Contract> getall() {
        return contractServicempl.getall();
    }

}
